//*********************************************************
//
// Output Registers used:
//   oPos - The vertex output position.
//   oT0  - original UV
//   oT1  - Position in light-space
//   oT2  - Light direction in tangentspace
//   oT5  - Camera direction in tangent space
//   oD0  - Light diffuse
//   oD1  - Light specular
//
//*********************************************************

// oPos = MVP * position
m4x4 r0, inPos, c[MODEL_VIEW_PROJECTION]
mov oPos, r0

// oT0 = texcoord
mov oT0, inUV

// oT1 = (position - LightPos)/LightRange
sub r1, inPos, c[VL_MODEL_SPACE_LIGHT_POS]
mul r1, r1, c[VL_PLIGHT_OORANGE_RANGE_SHADOWLENGTH_INTENSITY].x
mul r1, r1, c[VL_ATTENUATION_C_L_Q_TABLEMUL].w
mov oT1, r1

// r4 = TangentMatrix[-1] * (LightPos - position)
sub  r1, c[VL_MODEL_SPACE_LIGHT_POS], inPos      ; Light direction
dp3  r4.x, v3, r1
dp3  r4.y, v4, r1
dp3  r4.z, inNormal, r1
mov oT2.xyz, r4

// r4 = TangentMatrix[-1] * (CameraPos - position)
sub  r1, c[MODEL_SPACE_CAMERA_POS_OOFOG_RANGE], inPos      ; Camera direction
dp3  r4.x, v3, r1
dp3  r4.y, v4, r1
dp3  r4.z, inNormal, r1
mov oT5.xyz, r4

mov r0, c[MATERIAL_DIFFUSE_OPACITY]
mul r0.a, r0.a, inNormal.w
mul oD0, r0, c[VL_PLIGHT_DIFFUSE_1]

mov r0, c[MATERIAL_SPECULAR_POWER]
mul oD1.rgb, r0, c[VL_PLIGHT_SPECULAR_1]
mov oD1.a, c[CONSTANT_0_05_1_2].x
